package com.jcl.recruit.resume.provider;

import com.jcl.recruit.mapper.provider.SqlProvider;
import com.jcl.recruit.resume.model.ResumeWork;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class ResumeWorkSqlProvider implements SqlProvider<ResumeWork> {

    private static final String TABLE_NAME = "resume_work";

    public String insert(ResumeWork record) {
        BEGIN();
        INSERT_INTO(TABLE_NAME);
        
        if (record.getResumeId() != null) {
            VALUES("resume_id", "#{resumeId,jdbcType=INTEGER}");
        }

        if (record.getCorpCode() != null) {
            VALUES("corp_code", "#{corpCode,jdbcType=VARCHAR}");
        }
        
        if (record.getCompany() != null) {
            VALUES("company", "#{company,jdbcType=VARCHAR}");
        }
        
        if (record.getDuty() != null) {
            VALUES("duty", "#{duty,jdbcType=VARCHAR}");
        }
        
        if (record.getPosition() != null) {
            VALUES("position", "#{position,jdbcType=VARCHAR}");
        }
        
        if (record.getStartDate() != null) {
            VALUES("start_date", "#{startDate,jdbcType=VARCHAR}");
        }
        
        if (record.getEndDate() != null) {
            VALUES("end_date", "#{endDate,jdbcType=VARCHAR}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKey(ResumeWork record) {
        BEGIN();
        UPDATE(TABLE_NAME);
        
        if (record.getResumeId() != null) {
            SET("resume_id = #{resumeId,jdbcType=INTEGER}");
        }
        
        if (record.getCompany() != null) {
            SET("company = #{company,jdbcType=VARCHAR}");
        }
        
        if (record.getDuty() != null) {
            SET("duty = #{duty,jdbcType=VARCHAR}");
        }
        
        if (record.getPosition() != null) {
            SET("position = #{position,jdbcType=VARCHAR}");
        }
        
        if (record.getStartDate() != null) {
            SET("start_date = #{startDate,jdbcType=VARCHAR}");
        }
        
        if (record.getEndDate() != null) {
            SET("end_date = #{endDate,jdbcType=VARCHAR}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}